package com.alibaba.citrus.cr.mn.order.center.forecastorder.entity;

import com.alibaba.citrus.cr.common.util.SpringContextUtil;
import com.alibaba.citrus.cr.mn.order.center.facade.repository.ForecastOrderLineQueryRepository;
import com.alibaba.citrus.cr.mn.order.center.facade.repository.ForecastOrderLineWriteRepository;
import com.alibaba.citrus.cr.mn.order.center.facade.repository.ForecastOrderQueryRepository;
import com.alibaba.citrus.cr.mn.order.center.forecastorder.ability.ForecastOrderAbility;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.crforecastsales.sdo.ForecastOrderLineSDO;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yuanDeng
 * @Date 2021/9/15 15:13
 **/
@Getter
public class ForecastOrderLineEntity {
    private static final Log log = Log.getLogger(ForecastOrderLineEntity.class);

    private ForecastOrderLineSDO forecastOrderLineSDO;

    private static ForecastOrderQueryRepository forecastOrderRepository;

    private static ForecastOrderLineWriteRepository forecastOrderLineWriteRepository;

    private static ForecastOrderLineQueryRepository forecastOrderLineRepository;

    private static ForecastOrderAbility forecastOrderLineAbility;

    static {
        forecastOrderRepository = SpringContextUtil.getBean(ForecastOrderQueryRepository.class);
        forecastOrderLineRepository = SpringContextUtil.getBean(ForecastOrderLineQueryRepository.class);
        forecastOrderLineWriteRepository = SpringContextUtil.getBean(ForecastOrderLineWriteRepository.class);
        forecastOrderLineAbility = SpringContextUtil.getBean(ForecastOrderAbility.class);
    }

    public static ForecastOrderLineEntity of(ForecastOrderLineSDO forecastOrderLineSDO) {
        ForecastOrderLineEntity forecastOrderLineEntity = new ForecastOrderLineEntity();
        forecastOrderLineEntity.forecastOrderLineSDO = forecastOrderLineSDO;
        return forecastOrderLineEntity;
    }

    @Deprecated
    public static boolean analysis(List<ForecastOrderLineEntity> forecastOrderLineEntities) {
        List<ForecastOrderLineSDO> batchAnalysisOrdersRequest = new ArrayList<>();
        for (ForecastOrderLineEntity forecastOrderLineEntity : forecastOrderLineEntities) {
            batchAnalysisOrdersRequest.add(forecastOrderLineEntity.forecastOrderLineSDO);
        }
        return true;
    }

    @Deprecated
    public static boolean batchRefuseForecast(List<ForecastOrderLineEntity> forecastOrderLineEntities) {
        List<ForecastOrderLineSDO> batchAnalysisOrdersRequest = new ArrayList<>();
        for (ForecastOrderLineEntity forecastOrderLineEntity : forecastOrderLineEntities) {
            batchAnalysisOrdersRequest.add(forecastOrderLineEntity.forecastOrderLineSDO);
        }
        return true;
    }

    @Deprecated
    public static boolean updateDealStatus(List<ForecastOrderLineEntity> forecastOrderLineEntities) {
        List<ForecastOrderLineSDO> batchAnalysisOrdersRequest = new ArrayList<>();
        for (ForecastOrderLineEntity forecastOrderLineEntity : forecastOrderLineEntities) {
            batchAnalysisOrdersRequest.add(forecastOrderLineEntity.forecastOrderLineSDO);
        }
        for (Object obj : batchAnalysisOrdersRequest) {
            //订单进行分析分析后赋值，报保存
            ForecastOrderLineSDO forecastOrderLine = JSONObject.parseObject(JSONObject.toJSONString(obj), ForecastOrderLineSDO.class);
            boolean b1 = forecastOrderLineWriteRepository.updateForAnalysis(forecastOrderLine);
        }

        return true;
    }
}
